<?php

include('db_config.php');
include('Threads.php');

// Connect to the database (using db_config.php)

$db = db_connect();

// Setting these values determines what data will go into "Test_Threads"

for($annotator = 1; $annotator < 3 ; $annotator++)
{  for($filenumber = 1; $filenumber < 5 ; $filenumber++)
   {

// Get the relevant data from "Test_Annotations",
// which now has the data migrated from "Annotations"

$trees = mysql_query("SELECT tree FROM `Test_Threads` " .
               "WHERE filenumber = " . $filenumber . " " .
               "AND annotator = " . $annotator . ";")
         or die(mysql_error());

while($row = mysql_fetch_array($trees, MYSQL_ASSOC))
{  preg_match_all('/\d+/', $row["tree"], $tree);
   $treeB = $tree[0];
   $root = $treeB[0];
   $array = implode(",", $treeB);
   mysql_query("UPDATE test_annotations set thread = $root " .
               "WHERE filenumber = " . $filenumber . " " .
               "AND annotator = " . $annotator . " " .
               "AND postnum in ($array);")
        or die(mysql_error());

}
}
}

